<!DOCTYPE html>
<html>
<head>
    <title>运营设置</title>
    <#include "/header.html">
</head>
<body>
<div id="webpage"  v-cloak>
    <div class="padding">
        <div sclass="padding15-0">
            <div>
                <form @submit.prevent="save">
                    <div v-for="(cfg,key) in queryConfigList()">


                        <div v-if="key == 'operation.income.ratio'"  class="form-group">
                            <label class="block"><em class="key">{{cfg.paramKey}}</em>{{cfg.name}} <span class="tip">( {{cfg.remark}} )</span></label>
                            <div class="padding10">
                                <div class="form-group">
                                    <label>官方主播分成 <span class="tip">( 官方主播分成比例 <b class="red">{{parseFloat(form[key].profit2platform2user) * 100}}</b> % )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="form[key].profit2platform2user" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>公会分成 <span class="tip">( 公会分成比例 <b class="red">{{parseFloat(form[key].profit2platform2guild) * 100}}</b> % )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="form[key].profit2platform2guild" />
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div v-if="key == 'assets.payment.defaultMoneyList'" class="form-group">
                            <label class="block"><em class="key">{{cfg.paramKey}}</em>{{cfg.name}} <span class="tip">( {{cfg.remark}} )</span></label>
                            <div class="padding10">
                                <input type="text" class="form-control" v-model="defaultMoneyList" :placeholder="config[key].name" />
                            </div>
                        </div>

                        <div v-if="key == 'operation.income.guild2user.defaultProfitList'" class="form-group">
                            <label class="block"><em class="key">{{cfg.paramKey}}</em>{{cfg.name}} <span class="tip">( {{cfg.remark}} )</span></label>
                            <div class="padding10">
                                <input type="text" class="form-control" v-model="defaultProfitList" :placeholder="config[key].name" />
                            </div>
                        </div>

                        <div v-if="key == 'pay.rate.money2coin'"  class="form-group">
                            <label class="block"><em class="key">{{cfg.paramKey}}</em>{{cfg.name}} <span class="tip">( {{cfg.remark}} )</span></label>
                            <div class="padding10">
                                <div class="form-group">
                                    <label>全局比例 <span class="tip">( 充值１元兑换 <b class="red">{{form[key].globalRate}}</b> 金币 )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="form[key].globalRate" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>安卓客户端 <span class="tip">( 充值１元兑换 <b class="red">{{form[key].android}}</b> 金币 )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="form[key].android" />
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>苹果客户端 <span class="tip">( 充值１元兑换 <b class="red">{{form[key].ios}}</b> 金币 )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="form[key].ios" />
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div v-if="key == 'pay.withdraw.config'" class="form-group">
                            <label class="block"><em class="key">{{cfg.paramKey}}</em>{{cfg.name}} <span class="tip">( {{cfg.remark}} )</span></label>
                            <div class="padding10">
                                <div class="form-group">
                                    <label>是否启用验证</label>
                                    <div class="padding10">
                                        <label v-for="(v,k) in [{text:'启用',value:'1'},{text:'禁用',value:'0'}]" class="checkbox-inline">
											<input name="enable[]" type="radio" :value="v.value" v-model="form[key].enable" :checked="form[key].enable==v.value"> {{v.text}}
										</label>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label>支持银行列表 <span class="tip">( 支持银行列表请从 bank.sdk.codes 参数中选择 )</span></label>
                                    <div class="padding10">
                                        <input type="text" class="form-control" v-model="allowBanksList" />
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                    <div class="form-group">
                        <label></label>
                        <p><input type="submit" class="btn btn-primary" value="保存设置"/></p>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
Vue.config.debug = true
function get_request_url(qs) {
    var segment = location.pathname.replace('.html', '').split('/').pop();
    var url = str_format('app/config/{0}?{1}', segment, qs ? qs : '');
    return url;
}
var vm  = T.vm = new Vue({
	data:{
        active : '',
        config : {},
        form : {
            
        }
    },
	watch:{
        
    },
    created:function(){
        var vm = this;
        apiget(get_request_url(),function(res){
            if(res.code>0){
                vm.config = res.data;
                var form = {};
                $.map(res.data,function(value,key){
                    console.log([key,' -> ',value.paramValue].join(' '))
                    var type = value.type;
                    var value = value.paramValue;
                    if(type == 'object' || type == 'array'){
                        value = JSON.parse(value);
                    }
                    form[key] = value;
                    vm.$set(vm.form,key,value);
                })
                
                vm.$mount('#webpage');
            }
        })
    },
    computed:{
        defaultMoneyList : {
            get : function(){
                var vm = this;
                var value = vm.form['assets.payment.defaultMoneyList'];
                try{
                    return value.join(',');
                }
                catch(e){
                    console.log(value)
                    console.log(e);
                }
            },
            set : function(str){
                vm.form['assets.payment.defaultMoneyList'] = str.split(',')
            }
        },
        defaultProfitList : {
            get : function(){
                var vm = this;
                var value = vm.form['operation.income.guild2user.defaultProfitList'];
                try{
                    return value.join(',');
                }
                catch(e){
                    console.log(value)
                    console.log(e);
                }
            },
            set : function(str){
                vm.form['operation.income.guild2user.defaultProfitList'] = str.split(',')
            }
        },
        allowBanksList : {
            get : function(){
                var vm = this;
                var value = vm.form['pay.withdraw.config']['list'];
                try{
                    return value.join(',');
                }
                catch(e){
                    console.log(value)
                    console.log(e);
                }
            },
            set : function(str){
                vm.form['pay.withdraw.config']['list'] = str.split(',')
            }
        }
        
    },
	methods: {
        queryConfigList : function(str){
            if(!str){
                return this.config;
            }
            var keys = str.split(',');
            var ret = {};
            $.map(this.config,function(v,k){
                if($.inArray(k,keys)>-1){
                    ret[k] = v;
                }
            });
            return ret;
        },
        save : function(){
            var data = {};
            var vm = this;
            $.map(this.config,function(raw,key){
                var value  = vm.form[key];
                console.log([key,value])
                console.log(raw)
                if(raw.type != 'string'){
                    value = JSON.stringify(value,null,2);
                }
                data[key] = value;
            })
            console.log(data);
            postjson(get_request_url('action=post'),data).then(function(res){
                if(res.code>0){
                    alert('保存配置成功')
                }
                else{
                    alert(res.msg);
                }
                console.log(res);
            });
            return false;
        }
	}
});
</script>
</body>
</html>